package vn.com.pavibook.admin.service;

import java.io.File;
import java.io.IOException;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

@Service
public class FileUploadServiceImpl implements FileUploadService {

	@Override
	public boolean uploadFile(CommonsMultipartFile filea,
			String fullPathFileName, long maxSize)
			throws IllegalStateException, IOException {
		if (filea.getSize() > 0 && (filea.getSize() <= maxSize || maxSize == 0)) {
			File file = new File(fullPathFileName);
			file.mkdirs();
			filea.transferTo(file);
			return true;
		}

		throw new IOException();
	}
}
